home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / dev / c / ctags.lha / ctags-3.0.3 / options.c < prev    next >
C/C++ Source or Header  |  1999-02-17  |  44KB  |  1,511 lines

  1. /*****************************************************************************
  2. *   $Id: options.c,v 7.1 1998/12/07 01:38:00 darren Exp $
  3. *
  4. *   Copyright (c) 1996-1998, Darren Hiebert
  5. *
  6. *   This source code is released for free distribution under the terms of the
  7. *   GNU General Public License.
  8. *
  9. *   This module contains functions to process command line options.
  10. *****************************************************************************/
  11.  
  12. /*============================================================================
  13. =   Include files
  14. ============================================================================*/
  15. #include "general.h"
  16.  
  17. #ifdef HAVE_STDLIB_H
  18. # include <stdlib.h>        /* to declare malloc(), realloc() */
  19. #endif
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <ctype.h>    /* to declare toupper() */
  23.  
  24. #include "ctags.h"
  25. #define OPTION_WRITE
  26. #include "options.h"
  27.  
  28. #include "main.h"
  29. #include "debug.h"
  30.  
  31. /*============================================================================
  32. =   Defines
  33. ============================================================================*/
  34.  
  35. #define INVOCATION  "Usage: %s [options] [file(s)]\n"
  36.  
  37. #define CTAGS_ENVIRONMENT    "CTAGS"
  38. #define ETAGS_ENVIRONMENT    "ETAGS"
  39.  
  40. #define CTAGS_FILE    "tags"
  41. #define ETAGS_FILE    "TAGS"
  42.  
  43. #ifndef ETAGS
  44. # define ETAGS    "etags"        /* name which causes default use of to -e */
  45. #endif
  46.  
  47. /*  The following separators are permitted for list options.
  48.  */
  49. #define EXTENSION_SEPARATORS   "."
  50. #define IGNORE_SEPARATORS   ", \t\n"
  51.  
  52. #ifndef DEFAULT_FILE_FORMAT
  53. # define DEFAULT_FILE_FORMAT    2
  54. #endif
  55.  
  56. #if defined(MSDOS) || defined(WIN32) || defined(OS2) || defined(AMIGA) || defined(HAVE_OPENDIR)
  57. # define RECURSE_SUPPORTED
  58. #endif
  59.  
  60. /*============================================================================
  61. =   Data declarations
  62. ============================================================================*/
  63.  
  64. enum eOptionLimits {
  65.     MaxHeaderExtensions    = 100,    /* maximum number of extensions in -h option */
  66.     MaxSupportedTagFormat = 2
  67. };
  68.  
  69. typedef struct sOptionDescription {
  70.     int usedByEtags;
  71.     const char *const description;
  72. } optionDescription;
  73.  
  74. /*============================================================================
  75. =   Data definitions
  76. ============================================================================*/
  77.  
  78. static boolean StartedAsEtags = FALSE;
  79.  
  80. static const char *const CExtensionList[] = {
  81.     "c", NULL
  82. };
  83. static const char *const CppExtensionList[] = {
  84. #if !defined(MSDOS) && !defined(WIN32) && !defined(OS2) && !defined(__vms)
  85.     "C",    /* be careful on case-insensitive operating systems! */
  86. #endif
  87.     "c++", "cc", "cpp", "cxx", "h", "H", "hh", "hpp", "hxx", "h++", NULL
  88. };
  89. static const char *const EiffelExtensionList[] = {
  90.     "e", NULL
  91. };
  92. static const char *const FortranExtensionList[] = {
  93.     "f", "for", "ftn", "f77", "f90", "F", "FOR", "FTN", "F77", "F90", NULL
  94. };
  95. static const char *const JavaExtensionList[] = {
  96.     "java", NULL
  97. };
  98. static const char *const HeaderExtensionList[] = {
  99.     "h", "H", "hh", "hpp", "hxx", "h++", "inc", "def", NULL
  100. };
  101.  
  102. optionValues Option = {
  103.     {        /* include */
  104.     {    /* c */
  105.         TRUE,        /* -ic */
  106.         TRUE,        /* -id */
  107.         TRUE,        /* -ie */
  108.         TRUE,        /* -if */
  109.         TRUE,        /* -ig */
  110.         FALSE,        /* -im */
  111.         TRUE,        /* -in */
  112.         FALSE,        /* -ip */
  113.         TRUE,        /* -is */
  114.         TRUE,        /* -it */
  115.         TRUE,        /* -iu */
  116.         TRUE,        /* -iv */
  117.         FALSE,        /* -ix */
  118.         FALSE,        /* -iA */
  119.         FALSE        /* -iC */
  120.     },
  121.     {    /* eiffel */
  122.         TRUE,        /* -c */
  123.         TRUE,        /* -f */
  124.         TRUE        /* -l */
  125.     },
  126.     {    /* fortran */
  127.         TRUE,        /* -b */
  128.         TRUE,        /* -c */
  129.         TRUE,        /* -e */
  130.         TRUE,        /* -f */
  131.         TRUE,        /* -i */
  132.         TRUE,        /* -l */
  133.         TRUE,        /* -m */
  134.         TRUE,        /* -n */
  135.         TRUE,        /* -p */
  136.         TRUE,        /* -s */
  137.         TRUE        /* -t */
  138.     },
  139.     {    /* java */
  140.         TRUE,        /* -c */
  141.         TRUE,        /* -f */
  142.         TRUE,        /* -i */
  143.         TRUE,        /* -m */
  144.         TRUE,        /* -p */
  145.         FALSE,        /* -iA */
  146.         FALSE        /* -iC */
  147.     },
  148.     FALSE,        /* -iF */
  149.     TRUE,        /* -iS */
  150.     },
  151.     { NULL, 0, 0 },    /* -I */
  152.     FALSE,        /* -a */
  153.     FALSE,        /* -B */
  154.     FALSE,        /* -e */
  155. #ifdef MACROS_USE_PATTERNS
  156.     EX_PATTERN,        /* -n, --excmd */
  157. #else
  158.     EX_MIX,        /* -n, --excmd */
  159. #endif
  160.     NULL,        /* -p */
  161.     FALSE,        /* -R */
  162.     TRUE,        /* -u, --sort */
  163.     FALSE,        /* -V */
  164.     FALSE,        /* -x */
  165.     NULL,        /* -L */
  166.     NULL,        /* -o */
  167.     HeaderExtensionList,/* -h */
  168.     DEFAULT_FILE_FORMAT,/* --format */
  169.     FALSE,        /* --if0 */
  170.     FALSE,        /* --kind-long */
  171.     LANG_AUTO,        /* --lang */
  172.     {            /* --langmap */
  173.     CExtensionList,
  174.     CppExtensionList,
  175.     EiffelExtensionList,
  176.     FortranExtensionList,
  177.     JavaExtensionList,
  178.     },
  179.     FALSE,        /* --totals */
  180.     FALSE,        /* --line-directives */
  181. #ifdef DEBUG
  182.     0, 0        /* -D, -b */
  183. #endif
  184. };
  185.  
  186. /*----------------------------------------------------------------------------
  187. -   Locally used only
  188. ----------------------------------------------------------------------------*/
  189.  
  190. static optionDescription LongOptionDescription[] = {
  191.  {1,"  -a   Append the tags to an existing tag file."},
  192. #ifdef DEBUG
  193.  {1,"  -b <line>"},
  194.  {1,"       Set break line."},
  195. #endif
  196.  {0,"  -B   Use backward searching patterns (?...?)."},
  197. #ifdef DEBUG
  198.  {1,"  -D <level>"},
  199.  {1,"       Set debug level."},
  200. #endif
  201.  {0,"  -e   Output tag file for use with Emacs."},
  202.  {1,"  -f <name>"},
  203.  {1,"       Output tags to the specified file (default is \"tags\"; or \"TAGS\""},
  204.  {1,"       if -e is specified). If specified as \"-\", tags are written to"},
  205.  {1,"       standard output."},
  206.  {0,"  -F   Use forward searching patterns (/.../) (default)."},
  207.  {1,"  -h <list>"},
  208.  {1,"       Specifies a list of file extensions used for headers."},
  209.  {1,"       The default list is \".h.H.hh.hpp.hxx.h++\"."},
  210.  {1,"  -i <types>"},
  211.  {1,"       Nearly equivalent to --c-types=<types>."},
  212.  {1,"  -I <list | file>"},
  213.  {1,"       A list of tokens to ignore is read from either the command line,"},
  214.  {1,"       or the specified file (if leading character is '.', '/', or '\\')."},
  215.  {1,"       Particularly useful when a function definition or declaration"},
  216.  {1,"       contains some special macro before the parameter list."},
  217.  {1,"  -L <file>"},
  218.  {1,"       A list of source file names are read from the specified file."},
  219.  {1,"       If specified as \"-\", then standard input is read."},
  220.  {0,"  -n   Equivalent to --excmd=number."},
  221.  {0,"  -N   Equivalent to --excmd=pattern."},
  222.  {1,"  -o   Alternative for -f."},
  223.  {1,"  -p <path>"},
  224.  {1,"       Default path to use for all (relative path) filenames."},
  225. #ifdef RECURSE_SUPPORTED
  226.  {1,"  -R   Equivalent to --recurse=yes."},
  227. #else
  228.  {1,"  -R   Not supported on this platform."},
  229. #endif
  230.  {0,"  -u   Equivalent to --sort=no."},
  231.  {1,"  -V   Enable verbose messages describing actions on each source file."},
  232.  {1,"  -x   Print a tabular cross reference file to standard output."},
  233.  {1,"  --append=[yes|no]"},
  234.  {1,"       Indicates whether tags should be appended to existing tag file"},
  235.  {1,"       (default=no)."},
  236.  {1,"  --c-types=types"},
  237.  {1,"       Specifies a list of C/C++ language tag types to include in the"},
  238.  {1,"       output file. \"Types\" is a group of one-letter flags designating"},
  239.  {1,"       types of tags to either include or exclude from the output. Each"},
  240.  {1,"       letter or group of letters may be preceded by either '+' (default,"},
  241.  {1,"       if omitted) to add it to those already included, or '-' to exclude"},
  242.  {1,"       it from the output. In the absence of any preceding '+' or '-'"},
  243.  {1,"       sign, only those types listed in \"types\" will be included in the"},
  244.  {1,"       output. Tags for the following language contructs are supported"},
  245.  {1,"       (types are enabled by default except as noted):"},
  246.  {1,"          c   classes"},
  247.  {1,"          d   macro definitions"},
  248.  {1,"          e   enumerators (values inside an enumeration)"},
  249.  {1,"          f   function definitions"},
  250.  {1,"          g   enumeration names"},
  251.  {1,"          m   class, struct, and union members [off]"},
  252.  {1,"          n   namespaces"},
  253.  {1,"          p   function prototypes [off]"},
  254.  {1,"          s   structure names"},
  255.  {1,"          t   typedefs"},
  256.  {1,"          u   union names"},
  257.  {1,"          v   variable definit